package com.example.hellodemo.jump;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.example.hellodemo.R;

public class ABJumpActivity extends AppCompatActivity {
    private TextView textView;
    private Button jumpBtn;
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_b);

        Log.d("ABJumpActivity","---onCreate---");
        Log.d("ABJumpActivity", "taskId" + getTaskId() + ",  hash:" + hashCode());
        logtaskName();
        textView = findViewById(R.id.jump_b1);


        final Bundle bundle = getIntent().getExtras();
        textView.setText(bundle.getString("name") + ":" + bundle.getInt("age"));

        jumpBtn = findViewById(R.id.jump_b2);
        jumpBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // 返回数据到上一级
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("title","I am coming Back");
                intent.putExtras(bundle);
                setResult(Activity.RESULT_OK,intent); // 返回数据到上一级
                finish(); //关闭当前Activity
            }
        });





    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d("ABJumpActivity","---onNewIntent---");
        Log.d("ABJumpActivity", "taskId" + getTaskId() + ",  hash:" + hashCode());
        logtaskName();
    }

    private  void logtaskName(){
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
            Log.d("Activity",info.taskAffinity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }
}
